package org.lc.stk.model.question.attrs;

import org.hibernate.annotations.Comment;
import org.lc.stk.model.banks.CourseQuestionBank;
import org.lc.stk.model.user.User;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

/**
 * 用户自定义题型
 * 基于系统题型的扩展，允许用户在特定题库中自定义题型
 */
@Entity
@Table(name = "stk_user_question_type")
@Comment("用户自定义题型")
public class UserQuestionType extends QuestionType {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "creator_id", nullable = false)
    @Comment("创建者")
    private User creator;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "base_type_id", nullable = false)
    @Comment("基本题型")
    private SystemQuestionType baseQuestionType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "question_bank_id", nullable = false)
    @Comment("所属题库")
    private CourseQuestionBank questionBank;

    @Column(length = 500)
    @Comment("题型说明")
    private String description;

    @Column(length = 2000)
    @Comment("答题模板")
    private String template;

    protected UserQuestionType() {
        setType(Type.USER_DEFINED);
    }

    public UserQuestionType(String name, SystemQuestionType baseType, CourseQuestionBank bank, User creator) {
        this();
        setName(name);
        this.baseQuestionType = baseType;
        this.questionBank = bank;
        this.creator = creator;
        this.description = "基于" + baseType.getName() + "的自定义题型";
    }

    public SystemQuestionType getBaseQuestionType() {
        return baseQuestionType;
    }

    protected void setBaseQuestionType(SystemQuestionType baseQuestionType) {
        this.baseQuestionType = baseQuestionType;
    }

    public CourseQuestionBank getQuestionBank() {
        return questionBank;
    }

    protected void setQuestionBank(CourseQuestionBank questionBank) {
        this.questionBank = questionBank;
    }

    public User getCreator() {
        return creator;
    }

    protected void setCreator(User creator) {
        this.creator = creator;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTemplate() {
        return template;
    }

    public void setTemplate(String template) {
        this.template = template;
    }
}
